#include "loginform.h"
#include "ui_loginform.h"
#include "username.h"
#include "ui_username.h"
#include "password.h"
#include "ui_password.h"
#include<QPropertyAnimation>
LoginForm::LoginForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LoginForm)
{
    ui->setupUi(this);
    setWindowFlags(Qt::Popup);
    ui->lineEdit->hide();
    ui->lineEdit->move(510,120);
    connect(ui->frame->ui->lineEdit,&QLineEdit::textChanged,[=](){
        if(!(ui->frame->ui->lineEdit->text().isEmpty())&&!(ui->frame_2->ui->lineEdit->text().isEmpty())){
            ui->toolButton_2->setStyleSheet("QToolButton{border-image:url(:/png/登录3.png);border-style:solid;}  QToolButton:hover{border-image:url(:/png/登录1.png);}");
        }
        else{
            ui->toolButton_2->setStyleSheet("QToolButton{border-image:url(:/png/登录2.png);border-style:solid;}");
        }
    });//当lineedit改变时，判断密码和账户框是否为空，都不为空，登录按钮样式改变，以下信号槽同理
    connect(ui->frame_2->ui->lineEdit,&QLineEdit::textChanged,[=](){
        if(!(ui->frame->ui->lineEdit->text().isEmpty())&&!(ui->frame_2->ui->lineEdit->text().isEmpty())){
            ui->toolButton_2->setStyleSheet("QToolButton{border-image:url(:/png/登录3.png);border-style:solid;}  QToolButton:hover{border-image:url(:/png/登录1.png);}");
        }
        else if(!(ui->lineEdit->text().isEmpty())&&!(ui->frame_2->ui->lineEdit->text().isEmpty())){
            ui->toolButton_2->setStyleSheet("QToolButton{border-image:url(:/png/登录3.png);border-style:solid;}  QToolButton:hover{border-image:url(:/png/登录1.png);}");
        }
        else{
            ui->toolButton_2->setStyleSheet("QToolButton{border-image:url(:/png/登录2.png);border-style:solid;}");
        }
    });
    connect(ui->lineEdit,&QLineEdit::textChanged,[=](){
        if(!(ui->lineEdit->text().isEmpty())&&!(ui->frame_2->ui->lineEdit->text().isEmpty())){
            ui->toolButton_2->setStyleSheet("QToolButton{border-image:url(:/png/登录3.png);border-style:solid;}  QToolButton:hover{border-image:url(:/png/登录1.png);}");
        }
        else{
            ui->toolButton_2->setStyleSheet("QToolButton{border-image:url(:/png/登录2.png);border-style:solid;}");
        }
    });

}

LoginForm::~LoginForm()
{
    delete ui;
}

void LoginForm::on_toolButton_clicked()
{
    this->close();
}

void LoginForm::on_toolButton_5_clicked()
{
    ui->toolButton_5->setChecked(true);
    ui->toolButton_6->setChecked(false);

    if(!isNumber){
        QPropertyAnimation * animation = new QPropertyAnimation(ui->line_3,"geometry");
        animation->setDuration(500);
        animation->setStartValue(QRect(665,100,ui->line_3->width(),ui->line_3->height()));
        animation->setEndValue(QRect(495,100,ui->line_3->width(),ui->line_3->height()));
        animation->setEasingCurve(QEasingCurve::OutBounce);
        animation->start();
        ui->lineEdit->hide();
        ui->frame->show();
        ui->lineEdit->setText("");
    }
    isNumber = true;
}

void LoginForm::on_toolButton_6_clicked()
{
    ui->toolButton_5->setChecked(false);
    ui->toolButton_6->setChecked(true);

    if(isNumber){
        QPropertyAnimation * animation = new QPropertyAnimation(ui->line_3,"geometry");
        animation->setDuration(500);
        animation->setStartValue(QRect(495,100,ui->line_3->width(),ui->line_3->height()));
        animation->setEndValue(QRect(665,100,ui->line_3->width(),ui->line_3->height()));
        animation->setEasingCurve(QEasingCurve::OutBounce);
        animation->start();
        ui->lineEdit->show();
        ui->frame->hide();
        ui->frame->ui->lineEdit->setText("");
    }
    isNumber = false;

}
